home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group97b.txt
/
000088_icon-group-sender _Tue Oct 21 08:05:47 1997.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
3KB
Return-Path: <icon-group-sender>
Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
by cheltenham.cs.arizona.edu (8.8.7/8.8.7) with SMTP id IAA18421
for <icon-group-addresses@cheltenham.CS.Arizona.EDU>; Tue, 21 Oct 1997 08:05:46 -0700 (MST)
Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
id AA19492; Tue, 21 Oct 1997 08:05:46 -0700
Posted-Date: Mon, 20 Oct 1997 22:09:15 -0500 (CDT)
Date: Mon, 20 Oct 1997 22:09:15 -0500 (CDT)
From: Chris Tenaglia <cdt@post.its.mcw.edu>
To: gep2@computek.net
Cc: icon-group@cs.arizona.edu
Subject: Re: counting letters
In-Reply-To: <199710201711.MAA10989@axp.cmpu.net>
Message-Id: <Pine.SOL.3.96.971020220525.936A-100000@post.its.mcw.edu>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Brute force procedural icon...
____________________________________________________
procedure main()
count := table(0)
while line := read() do
every byte := !line do
if any(&letters,byte) then
count[byte] +:= 1
every byte := !&letters do
(count[byte] = 0) | write(byte," ",count[byte])
end
____________________________________________________
I'm sure there's briefer more collapsed
method. This also ignores letters that
don't occur, those with 0 occurrences.
Chris Tenaglia (system manager) | The future foretold,
Medical College of Wisconsin | The past explained,
8701 W. Watertown Plank Rd. | The present largely appologized for.
Milwaukee, WI 53226 (414)456-8765 | Organon to the Doctor
On Mon, 20 Oct 1997 gep2@computek.net wrote:
> Date: Mon, 20 Oct 1997 12:11:29 -0500
> From: gep2@computek.net
> To: icon-group@cs.arizona.edu
> Subject: counting letters
>
> >What would be the best way to design an Icon program that takes a text
> file as input, counts up the instances of every letter in the alphabet
> (ignoring other characters and distinguishing between uppercase and
> lowercase letters), and spits out the results of the count as output?
>
> Define "best"... smallest, simplest, fastest, most elegant?
>
> >For example, the following input
> abcdefghjijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()
> would produce the following output
>
> >a 1
> b 2
> [etc.]
> A 1
> b 2
> [etc.]
> [nothing for the non-alphabetic characters]
>
> In SNOBOL4+/SPITBOL, one program would be:
>
> -PLUSOPS 1
> T = TABLE()
> CHRSET = &LCASE &UCASE
> GETREC LINE = INPUT :F(EOF)
> COUNT LINE BREAK(CHRSET) ANY(CHRSET) . LET = ?(T[LET] = T[LET] + 1)
> + :S(COUNT)F(GETREC)
> EOF A = SORT(TABLE,1) :F(DONE)
> LIST OUTPUT = A[(N = N + 1),1] " " A[N,2] :S(LIST)
> END
>
> Gordon Peterson
> http://www.computek.net/public/gep2/
> Support the Anti-SPAM Amendment! Join at http://www.cauce.org/
>
>